package com.pro.grpcserver;

import com.google.common.net.HostAndPort;
import com.orbitz.consul.Consul;
import com.orbitz.consul.HealthClient;
import com.orbitz.consul.model.health.ServiceHealth;

import java.util.List;

public class NodesUtils {

	static List<ServiceHealth> nodesStatci = null;

	public  static List<ServiceHealth>  getServiceHealth(String ip){
		if(nodesStatci == null){
			Consul consul = Consul.builder().withHostAndPort(HostAndPort.fromString(ip + ":8500")).build();
			HealthClient healthClient = consul.healthClient();
			List<ServiceHealth> nodes = healthClient.getHealthyServiceInstances("promotion-service").getResponse();
			nodesStatci = nodes;
		}
		return nodesStatci;
	}

}
